<template>
  <div class="personal-center-container">
    <el-row :gutter="20">
      <el-col :lg="8" :md="12" :sm="24" :xl="8" :xs="24">
        <el-card shadow="hover">
          <div class="personal-center-user-info">
            <el-avatar :size="100" :src="avatar" @click.native="openDialog" />
            <div class="personal-center-user-info-full-name">
              {{ UserInfo.UserId }}
            </div>
            <div class="personal-center-user-info-description">
              {{ UserInfo.Authority }}
            </div>
            <!-- <div class="personal-center-user-info-follow">
              <a href="https://github.com/chuzhixin" target="_blank">
                <el-button round type="primary">
                  <vab-icon icon="group-line" />
                  Follow me
                </el-button>
              </a>
            </div> -->

            <ul class="personal-center-user-info-list">
              <li>
                <vab-icon icon="user-3-line" />
                {{ UserInfo.UserId }}
              </li>
              <li>
                <vab-icon icon="magic-line" />
                {{ UserInfo.UserName }}
              </li>
              <li>
                <vab-icon icon="women-line" />
                {{ UserInfo.PhoneNo }}
              </li>
              <li>
                <vab-icon icon="community-line" />
                {{ UserInfo.Authority }}
              </li>
            </ul>
          </div>
        </el-card>
      </el-col>
      <el-col :lg="16" :md="12" :sm="24" :xl="16" :xs="24">
        <el-card shadow="hover">
          <el-tabs v-model="activeName">
            <el-tab-pane label="基本信息" name="first">
              <el-col :lg="12" :md="16" :sm="24" :xl="12" :xs="24">
                <el-form ref="form" label-width="80px" :model="UserInfo">
                  <el-form-item label="用户Id">
                    <el-input v-model="UserInfo.UserId" readonly />
                  </el-form-item>
                  <el-form-item label="用户名">
                    <el-input v-model="UserInfo.UserName" readonly />
                  </el-form-item>
                  <el-form-item label="角色">
                    <el-input v-model="UserInfo.UserName" Authority />
                  </el-form-item>
                  <el-form-item label="密码">
                    <el-input v-model="UserInfo.PassWord" />
                  </el-form-item>
                  <el-form-item label="性别">
                    <el-select v-model="UserInfo.Sex" style="width: 100%">
                      <el-option label="男" value="男" />
                      <el-option label="女" value="女" />
                    </el-select>
                  </el-form-item>
                  <el-form-item label="电话">
                    <el-input v-model="UserInfo.PhoneNo" />
                  </el-form-item>
                  <el-form-item label="邮箱">
                    <el-input v-model="UserInfo.Email" />
                  </el-form-item>
                  <el-form-item>
                    <el-button type="primary" @click="onSubmit">保存</el-button>
                  </el-form-item>
                </el-form>
              </el-col>
            </el-tab-pane>
          </el-tabs>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script>
  import { mapGetters } from 'vuex'
  import { UserInfo, UserInfos } from '@/api/user'

  export default {
    name: 'PersonalCenter',
    data() {
      return {
        activeName: 'first',
        form: {},
        UserInfo: {},
      }
    },
    computed: {
      ...mapGetters({
        avatar: 'user/avatar',
      }),
    },
    created() {
      this.UserInfo = JSON.parse(localStorage.getItem('UserInfo'))
      console.log('UserInfo', !this.UserInfo)
      if (!this.UserInfo) {
        this.$router.replace({ name: 'login' })
      }
    },
    methods: {
      async onSubmit() {
        const data = await UserInfos(this.UserInfo)
        this.$baseMessage('保存成功', 'success', 'vab-hey-message-success')
      },
      openDialog() {
        this.$refs['vabCropper'].dialogVisible = true
      },
    },
  }
</script>

<style lang="scss" scoped>
  $base: '.personal-center';
  #{$base}-container {
    padding: 0 !important;
    background: $base-color-background !important;

    #{$base}-user-info {
      padding: $base-padding;
      text-align: center;

      :deep() {
        .el-avatar {
          img {
            cursor: pointer;
          }
        }
      }

      &-full-name {
        margin-top: 15px;
        font-size: 24px;
        font-weight: 500;
        color: #262626;
      }

      &-description {
        margin-top: 8px;
      }

      &-follow {
        margin-top: 15px;
      }

      &-list {
        margin-top: 18px;
        line-height: 30px;
        text-align: left;
        list-style: none;

        h5 {
          margin: -20px 0 5px 0;
        }

        :deep() {
          .el-tag {
            margin-right: 10px !important;
          }

          .el-tag + .el-tag {
            margin-left: 0;
          }
        }
      }
    }

    #{$base}-item {
      display: flex;

      i {
        font-size: 40px;
      }

      &-content {
        box-sizing: border-box;
        flex: 1;
        margin-left: $base-margin;

        &-second {
          margin-top: 8px;
        }
      }
    }
  }
</style>
